<?php

namespace app\index\controller;

use think\Controller;
use app\index\controller\DBclass;

class Xshou extends Controller
{
    public function AddHtml()
    {
        return $this->fetch('adds');
    }
    public function getAdd()
    {
        $arr = input('post.');
        $db = new \app\index\controller\DBclass();
        $res = $db->Add($arr);

        if ($res) {
            return redirect('shows');
        } else {
            return redirect('AddHtml');
        }
    }

    public function Shows()
    {
        $page = $_GET['page'] ?? 1;

        $name = request()->get('name','');

        $db = new \app\index\controller\DBclass();
        $res = $db->Show($page,$name);
        return $this->fetch('show', ['arr' => $res, 'page' => $page, 'name'=>$name]);
    }

    public function dels()
    {
        $id = $_GET['id'];
        $db = new \app\index\controller\DBclass();
        $res = $db->del($id);
        return redirect('shows');
    }

    public function updateHtml()
    {
        $id = $_GET['id'];
        $db = new \app\index\controller\DBclass();
        $res = $db->getOne( $id );
        return $this->fetch('updateHtml',['arr'=>$res]);
    }

    public function update()
    {
        $arr = $_POST;
        $db = new \app\index\controller\DBclass();
        $res = $db->update( $arr );
        return redirect('shows');
    }

    // public function cj()
    // {
    //     return $this->fetch('cj');
    // }
}
